package org.darcy.utils;

import static org.darcy.framework.constant.SysConstant.LOGIN_USER;

import org.darcy.entity.privilege.SysUser;

import cn.dev33.satoken.session.SaSession;
import cn.dev33.satoken.stp.StpUtil;

/**
 * 用户权限、角色工具
 */
public class UserTool {

	/**
	 * 获取登录用户
	 */
	public static SysUser getLoginUser() {
		if (StpUtil.isLogin()) {
			Object loginId = StpUtil.getLoginId();
			SaSession session = StpUtil.getSessionByLoginId(loginId);
			Object userObj = session.get(LOGIN_USER);
			if (userObj != null) {
				return (SysUser) userObj;
			}
		}
		return null;
	}

	/**
	 * 获取登录用户id
	 */
	public static Integer getLoginUserId() {
		SysUser user = getLoginUser();
		return user == null ? 0 : user.getId();
	}
	
	//IdWorker.get32UUID()

}
